package com.fenqing.leetcode.code.t700_800;

import com.fenqing.annotations.Execute;
import com.fenqing.core.Topic;

public class Topic704 extends Topic {
    /**
     * 构造器
     *
     * @param input1 输入
     * @param input2 输入
     */
    public Topic704(String input1, String input2) {
        super(input1, input2);
    }

    @Execute
    public int search(int[] nums, int target) {
        int p = 0, q = nums.length;
        while (p < q) {
            int mid = (p + q) / 2;
            if (nums[mid] == target) {
                return mid;
            } else if (nums[mid] < target){
                p = mid + 1;
            } else {
                q = mid;
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        //
        Topic704 topic704 = new Topic704(
                """
                [-1,0,3,5,9,12]
                """,
                "9"
        );
        int run = topic704.run();
        System.out.println(run);
    }
}
